package collectdemo13.map.hashmap;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

class Dog
{
	private String name = null;
	private int age = 0;
	public Dog(String name, int age)
	{
		super();
		this.setAge(age);
		this.setName(name);
	}
	public String getName()
	{
		return this.name;
	}
	public void setName(String name)
	{
		this.name = name;
	}
	public int getAge()
	{
		return this.age;
	}
	public void setAge(int age)
	{
		this.age = age;
	}
	@Override
	public String toString()
	{
		return "Dog [name=" + this.name + ", age=" + this.age + "]";
	}
	
}
public class HashMapDemo04
{

	/**
	 * @param args
	 */
	@SuppressWarnings("unchecked")
	public static void main(String[] args)
	{
		// TODO Auto-generated method stub
		Map<String,Dog> map = new HashMap<String,Dog>();
		Map<String,Dog> mapClone = null;
		//对象克隆技术
		mapClone = (HashMap<String,Dog>)(((HashMap<String,Dog>)map).clone());
		System.out.println("输入值之前判断是否为空："+map.isEmpty()+",个数:"+map.size());
		System.out.println("输入值之前判断是否为空："+mapClone.isEmpty()+",个数:"+mapClone.size());
		map.put("1山东", new Dog("lzq",30));
		map.put("2江苏", new Dog("sjj",30));
		map.put("3浙江", new Dog("wgc",30));
		System.out.println("1山东----"+map.get("1山东"));
		//法一输出方式entrySet() + iterator
		System.out.println("法一输出：");
		Set<Map.Entry<String,Dog>> set= map.entrySet();
		Iterator<Map.Entry<String,Dog>> iter = set.iterator();
		while(iter.hasNext())
		{
			Map.Entry<String,Dog> hs = (Map.Entry<String,Dog>)iter.next();
			System.out.println(hs.getKey()+"----------->"+hs.getValue());
		}
		//法二输出方式entrySet() + foreach
		System.out.println("法二输出：");
		for(Map.Entry<String,Dog> me : map.entrySet())
		{
			System.out.println(me.getKey()+"----------->"+me.getValue());
		}	
	}

}
